import 'package:flutter/material.dart';
import 'package:tender_flutter/constant/app_constant.dart';
import 'package:tender_flutter/dialog/free_permission_dialog.dart';
import 'package:tender_flutter/dialog/login_dialog.dart';
import 'package:tender_flutter/dialog/number_limit_dialog.dart';
import 'package:tender_flutter/init/default_app.dart';
import 'package:tender_flutter/page/home/model/user_info_entity.dart';
import 'package:tender_flutter/utils/sputils.dart';
import 'package:tender_flutter/widgets/animation_dialog.dart';

class PermissionManager {
  /// 是否可以查看信息
  static Future<bool> canCheck() async {
    return true;
    UserInfoEntity infoEntity = SPUtils.getUserInfo();
    if (!infoEntity.isVip()) {
      print("VIP不是");
      print("VIP不是${infoEntity.toJson()}");
      // 非VIP
      var result = await showFreePermissDialog(
          context: MyApp.navigatorState.currentContext);
      if (result == AppConstant.DIALOG_ACTION_CANCEL) {
        return false;
      } else {
        return false;
      }
    }
    print("VIP是");
    return true;
  }

  /// 登录判断
  static bool isLogin() {
    return SPUtils.isLogined();
  }

  /// 今日次数限制弹窗
  static Future showNumberLimitDialog({BuildContext context}) async {
    return showAnimationDialog(
        context: context ?? MyApp.navigatorState.currentContext,
        transitionType: TransitionType.inFromTop,
        builder: (context) {
          return NumberLimitDialog();
        });
  }

  /// 权益弹窗
  static Future showFreePermissDialog({BuildContext context}) async {
    return showAnimationDialog(
        context: context ?? MyApp.navigatorState.currentContext,
        transitionType: TransitionType.inFromTop,
        builder: (context) {
          return FreePermissionDialog();
        });
  }

  /// 登录弹窗
  ///
  static Future showLoginDialog({BuildContext context}) async {
    return showAnimationDialog(
        context: context ?? MyApp.navigatorState.currentContext,
        transitionType: TransitionType.inFromTop,
        builder: (context) {
          return LoginDialog();
        });
  }
}
